import Map = require('esri/Map');

class BasemapToggle {
    private container: string;
    private map: Map;
    private click: any;
    /**
     * 实例化底图切换小部件
     * @param container 底图切换部件所在的容器（选择器）
     * @param map 地图对象
     * @param click 回调函数
     */
    constructor(container: string, map: Map, click: any) {
        this.container = container;
        this.map = map;
        this.click = click;
    }
    /**
     * 启动小部件
     */
    startup() {
        this.initDom();
        this.initEvent(this.click);
    }
    private initDom() {
        $(this.container).load("/js/widgets/basemapToggle/template.html");
    }
    private initEvent(callback: any) {
        let _self = this;
        $(_self.container).hover(function () {
            $(".basemapToggle img").addClass("basemapToggleHover");
        }, function () {
            $(".basemapToggle img").removeClass("basemapToggleHover");
        })
        $(_self.container).on("click", ".basemapToggle", function () {
            if ($(this).attr("name") === "geoq") {
                callback($(this).attr("name"));
                $(this).attr("name", "tdt");
            } else {
                callback($(this).attr("name"));
                $(this).attr("name", "geoq");
            }
        });
    }
}
export default BasemapToggle;